<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">


	<head>
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title></title>
		<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" />
		<link href="Font-Awesome/css/font-awesome.min.css" rel="stylesheet" />
		<link href="style/main.css" rel="stylesheet" />
	</head>

	<body>
		<div id="wrapper">
			<div id="navbar">
				<div class="logo"></div>
				<ul class="navbox">
					<li class="in" data-src="index.html">数据列表</li>
					<li data-src="addBanner.html">添加banner</li>
					<li data-src="addCase.html">添加案例</li>
					<li data-src="addActivity.html">添加文章</li>
				</ul>
			</div>
			<div id="main">
				<div class="content">
					<div class="row">
						<div class="col-sm-12">
							<div class="row">
								<div class="col-md-6 col-sm-12">
									<div class="optionbtnbox">
										<div class="optionbtn optionbtn1 in">banner</div>
										<div class="optionbtn optionbtn2">案例</div>
										<div class="optionbtn optionbtn3">文章</div>
									</div>
								</div>
							</div>
							<div class="table-responsive">
								<table id="table" class="table table-hover table-bordered">
									<thead>
										<tr>
											<th>编号</th>
											<th>图片</th>
											<th class="th3">标题</th>
											<th>创建时间</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody id="tbody">
										
									</tbody>
								</table>
							</div>
							<div class="paging">
								<ul class="pagination" id="pagination"></ul>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<div class="imgpage Popup">
			<div class="imgbox Popup-content">
				<div class="closebtn">
					<span class="icon-remove"></span>
				</div>
				<img src="" class="big-img" alt="Responsive image" />
			</div>
		</div>
		<script th:src="@{script/jquery-min.js}"></script>
		<script th:src="@{script/ishoock.tools.js}"></script>
		<script th:src="@{script/main.js}"></script>
		<script th:src="@{bootstrap/js/bootstrap.min.js}"></script>
		<script th:src="@{bootstrap/js/bootstrap-paginator.js}"></script>
		<script>
		
		
		
		  var  tab_index = 1;
			$(function() {
				
				//点击导航栏
				$("#navbar .navbox li").on("click",function(){
					window.location.href=$(this).attr("data-src");
				});
				getData2();
				//点击删除按钮
				$("#tbody").on("click", ".delbtn", function() {
					
					 console.log(tab_index);
			      var id_value =  $(this).parents("tr").attr('id');
			      console.log(id_value);
			//banner 删除
			   if(tab_index == 1){
				   $.post("/banner/deleteById",{id:id_value},
						   function(returndata){
						
						     var code =  parseInt(returndata.code);
				        	  if(code==1){
				        		  getData2() ;
				        	  }
						   });
	
			   }
				//案例 删除
			   if(tab_index == 2){
				   
				   $.post("/cases/deletecase",{id:id_value},
						   function(returndata){
						     var code =  parseInt(returndata.code);
				        	  if(code==1){
				        		  getData() ;
				        	  }
						   });
				  
			   }
				//文章 删除
			   if(tab_index == 3){
				   $.post("/opinion/deleteById",{id:id_value},
						   function(returndata){
						     var code =  parseInt(returndata.code);
				        	  if(code==1){
				        		  getData3() ;
				        	  }
						   });
				  
			   }
			 
				});
				//点击编辑按钮
				$("#tbody").on("click", ".editbtn", function() {
					
					 console.log(tab_index);
				      var id_value =  $(this).parents("tr").attr('id');
				      console.log(id_value);
					if($(".optionbtn1").hasClass("in")){
						window.location.href="addBanner.html?id="+id_value+"&&tab_index="+tab_index;
					}else if($(".optionbtn2").hasClass("in")){
						window.location.href="addCase.html?id="+id_value+"&&tab_index="+tab_index;
					}else if($(".optionbtn3").hasClass("in")){
						window.location.href="addActivity.html?id="+id_value+"&&tab_index="+tab_index;
					} 
				});
				//点击banner,案例,文章按钮
				$(".optionbtn").on("click", function() {
					if($(this).index() == 0) {
						$(".optionbtn").removeIn();
						$(".optionbtn").eq(0).in();
						tab_index = 1;
						getData2();
					} else if($(this).index() == 1) {
						$(".optionbtn").removeIn();
						$(".optionbtn").eq(1).in();
						tab_index = 2;
						getData();
					} else if($(this).index() == 2) {
						$(".optionbtn").removeIn();
						$(".optionbtn").eq(2).in();
						tab_index = 3;
						getData3();
					}
				});
				
				//点击查看图片
				$("#tbody").on("click","img",function(){
					$(".Popup").fadeIn();
					$(".Popup .big-img").attr("src",$(this).attr("src"));
				});
				//点击关闭按钮
				$(".Popup .closebtn").on("click", function() {
					$(".Popup").fadeOut();
				});
			});

			
			function getData3() {
				$("#tbody").empty();
				$(".th3").html("标题");
	

				$.get("/opinion/alllist", { },
						  function(data){
					 console.log(data);
		        	  var code =  parseInt(data.code);
		        	  var dataArray = data.result;
		        	  if(code==1){
		        		  
		        			for(var i = 0; i < dataArray.length; i++) {
		        				var obj = dataArray[i];
		        			
		        				var item = '<tr id ='+obj.id+'>' +
		    						'<td>'+(i+1)+'</td>' +
		    						'<td><img class="seeimg" src="'+ obj.imgUrl+'"/></td>' +
		    						'<td>'+ obj.tittle+'</td>' +
		    						'<td>'+ obj.timeStr+'</td>' +
		    						'<td>' +
		    						'<button class="btn btn-default editbtn">编辑</button>' +
		    						'<button class="btn btn-default delbtn">删除</button>' +
		    						'</td>' +
		    						'</tr>';			
		    					$("#tbody").append(item);
		    				}
		   
		        		
		        	  }else{
	
		        	  }
						 
			 });
			
			}
			// 案例
			function getData() {
				$("#tbody").empty();
				$(".th3").html("标题");
	

				$.get("/cases/list", { },
						  function(data){
					 console.log(data);
		        	  var code =  parseInt(data.code);
		        	  var dataArray = data.result;
		        	  if(code==1){
		        		  
		        			for(var i = 0; i < dataArray.length; i++) {
		        				var obj = dataArray[i];
		        			
		    					var item = '<tr id ='+obj.id+'>' +
		    						'<td>'+(i+1)+'</td>' +
		    						'<td><img class="seeimg" src="'+ obj.imgUrl+'"/></td>' +
		    						'<td>'+ obj.tittle+'</td>' +
		    						'<td>'+ obj.timeStr+'</td>' +
		    						'<td>' +
		    						'<button class="btn btn-default editbtn">编辑</button>' +
		    						'<button class="btn btn-default delbtn">删除</button>' +
		    						'</td>' +
		    						'</tr>';			
		    					$("#tbody").append(item);
		    				}
		   
		        		
		        	  }else{
	
		        	  }
						 
			 });
			
			}
			

			// banner
			function getData2() {
				$("#tbody").empty();
				$(".th3").html("外链");

					$.get("/banner/alllist", { },
							  function(data){
						 console.log(data);
			        	  var code =  parseInt(data.code);
			        	  var dataArray = data.result;
			        	  if(code==1){
			        		  
			        			for(var i = 0; i < dataArray.length; i++) {
			        				var obj = dataArray[i];
			        			
			        				var item = '<tr id ='+obj.id+'>' +
			    						'<td>'+(i+1)+'</td>' +
			    						'<td><img class="seeimg" src="'+ obj.imgUrl+'"/></td>' +
			    						'<td>'+ obj.linkUrl+'</td>' +
			    						'<td>'+ obj.timeStr+'</td>' +
			    						'<td>' +
			    						'<button class="btn btn-default editbtn">编辑</button>' +
			    						'<button class="btn btn-default delbtn">删除</button>' +
			    						'</td>' +
			    						'</tr>';			
			    					$("#tbody").append(item);
			    				}
			   
			        		
			        	  }else{
		
			        	  }
							 
				 });
				
			
			}
			
	
			
		</script>
	</body>

</html>